perm filename PROB7.PUB[LSP,JRA]10 blob
sn#305708 filedate 1977-09-17 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 .GROUP
C00005 ENDMK
C⊗;
.GROUP
.CENT(Problems involving %3prog%*)
.BEGIN SELECT 1;INDENT 0,17;
.NL
1.##Write %3prog%*-versions of the following functions (or predicates).
.SBPR;
a.##%3member <= λ[[x;y] ...]%1:%3 x%1 is atomic; %3y%* is a list of atoms. %3member%* is to
return %et%* just in the case that %3x%* is one of the elements in %3y%*.
.end
.APART
.GROUP;
.SBPR
b.##The factorial function.
.SBPR
c.##delete <= λ[[x;y] ... ]%1: %3x%1 is atomic; %3y%* is a list of atoms. %3delete%* is to
return a list which looks like %3y%*, except all occurrences of %3x%*
have been deleted.
.SBPR
d.##The %3append%* function.
.APART
.GROUP;
.SBPR
e.##%3last <= λ[[x] ...]%1: %3x%1 is a non-empty list. %3last%* is to return the last
element in %3x%*.
.SBPR
f.##Now write the S-expr translations of each of your functions.
.NL
2.##What is necessary to extend the evaluator to recognize %3prog%* and friends?
.NL
3.##The %3go[cdr[...]]%*-construct on {yon(P25)} is better handled with a %2⊗→case
statement↔←%*. A typical syntax for such might be:
.P70:
.BOXA
←case<index>of <form%41%*>; ... ;<form%4n%*>.
.BOXB
.ONCE INDENT 4,4;
<index> is to evaluate to an integer, i. Where 0<i≤n. The i%8th%* <form> of the
case-statement is executed, and is the value of the statement.
Give a representation for the case statement and extend the evaluator to recognize
it.
.apart
.group
.NL
4.##Some languages allow
constructs like:
.BOXA
.BEGIN TURN OFF "←";CENTER;
(%2if%* p(x) %2then%* x %2else%* y) ← exp, which is to mean the same as:
.BOXB
%2if%* p(x) %2then%* x← exp %2else%* y ← exp
.END
.ONCE INDENT 4,4;
Can such a construct be written in LISP?
.apart
.NL
5.##Compare the %3prog%* version of %3length%* on {yon(P45)} with
%3length%41%1 on {yon(P19)}. Do you see any interesting relationships?